﻿@model PetaPoco.Page<Shop.Wares.Models.AnyWares>
@{
    //商品信息分布页
    Layout = null;
}
<table class="table table-bordered table-striped table-hover">
    <tr>
        <td>商品ID</td>
        <td>商品名</td>
        <td>所属类别</td>
        <td>所属子类别</td>
        <td>原价</td>
        <td>现价</td>
        <td>销售量</td>
        <td>库存</td>
        <td>商品描述</td>
        <td>图片</td>
        <td>存储地址</td>
        <td>管理</td>
    </tr>
    @if (Model.Items.Count == 0)
            {
        <tr>
            <td colspan="12">暂无数据</td>
        </tr>
    }
    else
    {
        foreach (var item in Model.Items)
        {
<tr>
    <td>@item.WID</td>
    <td>@item.WName</td>
    <td>@item.CName</td>
    <td>@item.SCName</td>
    <td>@item.OPrice</td>
    <td>@item.PPrice</td>
    <td>@item.SaleNum</td>
    <td>@item.Stock</td>
    <td>@item.Describe</td>
    <td>
        <img src="@item.Url" style="width:50px;height:50px;" />
    </td>
    <td>@item.bookLocation</td>
    <td>
        <a href="UpdateWares-@item.WID" class="btn btn-default">修改</a>
        <input type="button" class="btn btn-default" value="删除" onclick="del('@(item.WID)')" />
        <input type="button" class="btn btn-default" value="置顶" onclick="stick('@(item.WID)')" />
        @if (item.Status == 0)
        {
            <input type="button" class="btn btn-default" value="下架" onclick="DownFrame(@(item.WID))" />
        }
        else
        {
            <input type="button" class="btn btn-default" value="上架" onclick="UpFrame(@(item.WID))" />
        }
    </td>
</tr>
        }
    }
</table>
<div class="btn-toolbar" role="toolbar">
    @if (Model.TotalPages <= 1)
            {
        <div class="btn-group" role="group">
            <input type="button" class="btn btn-default disabled" value="首页" onclick=""/>
            <input type="button" class="btn btn-default disabled" value="上一页" onclick="" />
            <input type="button" class="btn btn-default disabled" value="下一页" onclick="" />
            <input type="button" class="btn btn-default disabled" value="尾页" onclick="" />
        </div>
    }
    else if (Model.CurrentPage == 1 && Model.TotalPages != 1)
    {
        <div class="btn-group" role="group">
            <input type="button" class="btn btn-default disabled" value="首页" onclick="" />
            <input type="button" class="btn btn-default disabled" value="上一页" onclick="" />
            <input type="button" class="btn btn-default" value="下一页" onclick="NextPage()" />
            <input type="button" class="btn btn-default " value="尾页" onclick="Shadowe()" />
        </div>
    }
    else if (Model.CurrentPage > 1 && Model.CurrentPage < Model.TotalPages)
    {
        <div class="btn-group" role="group">
            <input type="button" class="btn btn-default" value="首页" onclick="HomePage()" />
            <input type="button" class="btn btn-default" value="上一页" onclick="PreviousPage()" />
            <input type="button" class="btn btn-default" value="下一页" onclick="NextPage()" />
            <input type="button" class="btn btn-default " value="尾页" onclick="Shadowe()" />
        </div>
    }
    else if (Model.CurrentPage == Model.TotalPages && Model.CurrentPage != 1)
    {
        <div class="btn-group" role="group">
            <input type="button" class="btn btn-default" value="首页" onclick="HomePage()" />
            <input type="button" class="btn btn-default" value="上一页" onclick="PreviousPage()" />
            <input type="button" class="btn btn-default disabled" value="下一页" onclick="" />
            <input type="button" class="btn btn-default disabled" value="尾页" onclick="" />
        </div>
    }
    <a class="btn btn-default">第@(Model.CurrentPage)页/共@(Model.TotalPages)页</a>

    <div class="col-lg-2">
        <div class="input-group">
            <input type="text" class="form-control" placeholder="输入页码" id="pagenum">
            <span class="input-group-btn">
                <button class="btn btn-default" type="button" id="GO" onclick="GoPage()">Go!</button>
            </span>
        </div>
    </div>
</div>
<script type="text/javascript">
     //首页
    function HomePage() {
        JumpPage("1");
    }
    //下一页
    function NextPage()
    {
        JumpPage("@(Model.CurrentPage+1)");
    }
    //上一页
    function PreviousPage()
    {
        JumpPage("@(Model.CurrentPage-1)");
    }
    //尾页
    function Shadowe()
    {
        JumpPage("@(Model.TotalPages)");
    }
    //跳转到页数
    function GoPage()
    {
        var page = $("#pagenum").val();
        if (page == "") {
            alert("请输入跳转的页数");
        }
        else if (page < 1) {
            alert("请输入正确的页数");
        }
        else if (page >@(Model.TotalPages))
        {
            alert("输入不能超过总页数");
        }
        else
        {
            JumpPage(page)
        }
    }
    function JumpPage(Page)
    {
        var CID = $("#CID").val();
        var SCID = $("#SCID").val();
        var WName = $("#WName").val();
        var Status = $("#Status").val();
        $.ajax({
            cache: false,//是否从缓存中读取
            type: 'post',//方式
            url: '@Url.Action("_WaresSearch", "Wares")',//地址
            data: { CID: CID, SCID: SCID, WName: WName, Page: Page },
            dataType: 'text',//返回数据格式
            success: function (data) {
                $("#main").html(data);
            },
            error: function () {
                alert("Ajax调用出错请与管理员联系");
            }
        });
    }
</script>